package tool;

import cn.hutool.core.map.MapUtil;
import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONObject;

import java.io.IOException;
import java.util.*;

/**
 * Created by Intellij IDEA.
 * User:  老赵
 * Date:  2023/7/20
 */
public class Music{
    public static HashMap<String,String> musicMap = MapUtil.newHashMap();

    /**
     * 个人比较喜欢的一首歌，用的是网易云的音乐地址
     * 如果需要更换，打开本地网易云客户端，找到音乐然后右击分享，找到音乐id替换下面url的id就可以。
     */
    static {
        musicMap.put("name","无赖");
        musicMap.put("url","http://music.163.com/song/media/outer/url?id=1329722731");
        musicMap.put("picurl","https://bkimg.cdn.bcebos.com/pic/b219ebc4b74543a936e3852b1e178a82b8011458");
        musicMap.put("artistsname","太子基");
    }

    public static void getMusic(){
        String url = "https://api.uomg.com/api/rand.music?sort=热歌榜&format=json";
        String html = HttpUtil.get(url);
        JSONObject obj = new JSONObject(html);
        JSONObject data = obj.getJSONObject("data");
        musicMap.clear();
        musicMap.put("name",data.getStr("name"));
        musicMap.put("url",data.getStr("url"));
        musicMap.put("picurl",data.getStr("picurl"));
        musicMap.put("artistsname",data.getStr("artistsname"));
    }
}
